﻿Partial Public Class PictureBoxEventControl

    Private m_AvailableImages As List(Of MediaFile)

    Public Sub New(ByVal p_AvailableImages As List(Of MediaFile))
        InitializeComponent()
        m_AvailableImages = p_AvailableImages
        ComboImages.ItemsSource = AvailableImagesIDs

    End Sub



    Public Property AvailableImages() As List(Of MediaFile)
        Get
            Return m_AvailableImages
        End Get
        Set (ByVal value As List(Of MediaFile))
            m_AvailableImages = value
        End Set
    End Property

    Public Property AvailableImagesIDs() As List(Of Integer)
        Get
            Dim l_IDs = (From l_Image In m_AvailableImages Select l_Image.ID).ToList
            Return l_IDs
        End Get
        Set(ByVal value As List(Of Integer))

        End Set

    End Property


    Private Sub ComboImages_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)

        Dim l_imgs As New ImageSourceConverter
        Dim l_event = CType(Me.DataContext, EventBase)
        Dim l_mediaFile = (From l_file In m_AvailableImages Where l_file.ID = l_event.BackroundImageID Select l_file).Single
        Dim l_ImageSource = CType(l_imgs.ConvertFromString(l_mediaFile.Path), ImageSource)
        ImageBrush1.ImageSource = l_ImageSource


    End Sub
End Class
